CC = gcc
OPT = -w -I.

#OBJ CLIENT
OBJC = client.o log.o lock.o config-client.o transfert-client.o httpserver.o base64.o tri-fichier.o

#OBJ SERVER
OBJS = server.o log.o lock.o config-server.o transfert-server.o


# COMMUN >>>>>>
log.o: log.c log.h
	$(CC) -c log.c $(OPT)

lock.o: lock.c lock.h
	$(CC) -c lock.c $(OPT)

clean:
	@rm -rf *.o

psclean:
	-killall qube-client
	-killall qube-server
# COMMUN <<<<<<


# CLIENT >>>>>>
run-client: client
	@echo
	@echo "-qube-client start----------------------------"
	@echo
	@./qube-client
	@echo
	@echo "-qube-client end------------------------------"
	@echo

client: $(OBJC)
	$(CC) $(OBJC) -o qube-client

client.o: client.c
	$(CC) -c client.c $(OPT)

config-client.o: config-client.c config-client.h
	$(CC) -c config-client.c $(OPT)

transfert-client.o: transfert-client.c transfert-client.h
	$(CC) -c transfert-client.c $(OPT)

httpserver.o: httpserver.c httpserver.h
	$(CC) -c httpserver.c $(OPT)
	
base64.o: base64.c base64.h
	$(CC) -c base64.c $(OPT)
	
tri-fichier.o: tri-fichier.c tri-fichier.h
	$(CC) -c tri-fichier.c $(OPT)
# CLIENT <<<<<<


# SERVER >>>>>>
run-server: server
	@echo
	@echo "-qube-server start----------------------------"
	@echo
	@./qube-server
	@echo
	@echo "-qube-server end------------------------------"
	@echo

server: $(OBJS)
	$(CC) $(OBJS) -o qube-server

server.o: server.c
	$(CC) -c server.c $(OPT)

config-server.o: config-server.c config-server.h
	$(CC) -c config-server.c $(OPT)

transfert-server.o: transfert-server.c transfert-server.h
	$(CC) -c transfert-server.c $(OPT)
# SERVER <<<<<<

# INSTALL >>>>>>
install: install-client install-server

install-client: client etc-client insdb
	cp -f qube-client /usr/bin/
	cp -f conf/qube.css /var/qube/

install-server: client etc-server insvar
	cp -f qube-server /usr/bin/

etc-client: insetc
	cp -f conf/qube-client.conf /etc/qube/
	cp -f conf/qube-client.list /etc/qube/
	
etc-server: insetc
	cp -f conf/qube-server.conf /etc/qube
	cp -rf report_builder.d/ /etc/qube/report_builder.d/
	cp -f report_builder.sh /etc/qube/
	chmod u+x /etc/qube/report_builder.sh

insetc:
	mkdir -p /etc/qube

insvar:
	mkdir -p /var/qube

insdb: insvar
	mkdir -p /var/qube/db
	
cleandb:
	rm -rf /var/qube/db/*
	
# INSTALL <<<<<<

